﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Bear.Library.WinForm
{
    public class KeyBox : TextBox
    {



        private Keys _KeyCode = Keys.None;

        public Keys KeyCode
        {
            get
            {
                return this._KeyCode;
            }
            set
            {
                this._KeyCode = value;
                this.Text = this.KeyCode == Keys.None ? string.Empty : this.KeyCode.ToString();
            }
        }



        protected override void OnKeyDown(KeyEventArgs e)
        {
            base.OnKeyDown(e);
            this.KeyCode = e.KeyCode;
            this.Text = this.KeyCode.ToString();
            this.SelectionStart = this.Text.Length;

        }

        protected override void OnKeyPress(KeyPressEventArgs e)
        {
            base.OnKeyPress(e);
            e.Handled = true;
        }
    }
}
